function throttle<A extends any[], R>(
  fn: (...args: A) => R,
  delay?: number,
): (...args: A) => void {
  // let timer;
  // return function (...args) {
  //   if (!timer) {
  //     timer = setTimeout(() => {
  //       timer = null;
  //       fn.apply(this, args);
  //     }, delay);
  //   }
  // };
  let time = Date.now();
  return function (...args) {
    const now = Date.now();
    if (now > time + delay) {
      time = now;
      fn.apply(this, args);
    }
  };
}

export default throttle;
